using HotelManager.BLL;
using HotelManager.DAL;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Windows.Forms;

namespace HotelManager.UI
{
    static class Program
    {
        public static IHost LocalHost { get; private set; }

        /// <summary>
        ///  The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            LocalHost = CreateHostBuilder().Build();
            StartMessagePump(LocalHost);
        }
        
        public static IHostBuilder CreateHostBuilder()
        {
            return Host.CreateDefaultBuilder()
                .ConfigureServices(services =>
                {
                    services.AddScoped<HotelDbContext>();
                    services.AddScoped<AdminManager>();
                    services.AddScoped<DishListManager>();
                    services.AddScoped<GuestManager>();
                    services.AddScoped<ResideStateManager>();
                    services.AddScoped<RoomStateManager>();
                    services.AddScoped<RoomManager>();
                    services.AddScoped<StatisticsManager>();
                    services.AddScoped<TypeManager>();


                    services.AddScoped<IAdminService, AdminService>();
                    services.AddScoped<IDishListService, DishListService>();
                    services.AddScoped<IGuestService, GuestService>();
                    services.AddScoped<IResideStateService, ResideStateService>();
                    services.AddScoped<IRoomStateService, RoomStateService>();
                    services.AddScoped<IRoomService, RoomService>();
                    services.AddScoped<IStatisticsService, StatisticsService>();
                    services.AddScoped<ITypeServicer, TypeServicer>();

                    services.AddTransient<FrmAdmin>();
                    services.AddTransient<FrmBase>();
                    services.AddTransient<FrmChec>();
                    services.AddTransient<FrmDish>();
                    services.AddTransient<FrmGuestInfo>();
                    services.AddTransient<FrmLock>();
                    services.AddTransient<FrmLogin>();
                    services.AddTransient<FrmMain>();
                    services.AddTransient<FrmRoomInfo>();
                    services.AddTransient<FrmRoomType>();
                });                
        }

        static void StartMessagePump(IHost host)
        {
            using (var scope = host.Services.CreateScope())
            {
                var loginForm = scope.ServiceProvider.GetRequiredService<FrmLogin>();
                Application.Run(loginForm);
            }
        }
    }
}
